#ifndef TOUC_H
#define TOUC_H
#include "helpfunc.h"
#include "cli.h"

class touc
{
public:
    touc(){};
    static void start()
    {
        helpFunc::ini("df");
        mybuf w;
        w.writeArr2(helpFunc::con_serverKey);
        auto t = helpFunc::getTime();
        w.writeQ(t);
        w.writeQ(t);
        w.writeDWord(helpFunc::con_portsNum);
        w.writeByte(helpFunc::con_key.size());
        w.writeArr2(helpFunc::con_key);
        w.writeDWord(500);
        w.writeDWord(200*1024);
        w.writeDWord(8080);
        w.writeDWord(helpFunc::serverPackLen);
        w.writeDWord(helpFunc::serverSenLen);
        w.writeDWord(200*1024);
        double ef = helpFunc::con_packEffectTime / 1000.0;
        double timeout = helpFunc::con_timeoutInternal / 1000.0;
        w.writeDouble(ef);
        w.writeDouble(timeout);
        int sendSock =  socket (AF_INET, SOCK_DGRAM, 0);
        helpFunc::udpWrite(sendSock,w.data,helpFunc::serverIp,helpFunc::server_port,true);
        auto v=helpFunc::udpRead(sendSock);
        w = mybuf(v);
        auto xx=w.readQ();
        xx = w.readQ();
         deque<int> d;
        for(int i=0;i<helpFunc::con_portsNum;i++)
        {
            int t=  w.readWord();
            std::cout<<t<<",";
            d.push_back(t);
        }
       cout<<endl;
       cli a(d);
       a.doAccept();
       while (1) {
           a.work();
       }
    }
};

#endif // TOUC_H
